package com.xxl.job.admin.controller;

import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
import com.xxl.job.admin.core.trigger.TriggerTypeEnum;
import com.xxl.job.admin.core.util.JacksonUtil;
import com.xxl.job.core.biz.model.ReturnT;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author bbshi
 * @date 2023/1/4 9:30
 */
@RestController
@RequestMapping("/pkpm/jobinfo")
public class PkpmJobInfoController {

    @RequestMapping("/trigger")
    public ReturnT<String> triggerJob(int id, String executorParam, String addressList) {
        // force cover job param
        if (executorParam == null) {
            executorParam = "";
        }
        // 封装用户信息到executorParam参数中
        Map map = JacksonUtil.readValue(executorParam, Map.class);
        // todo 获取用户信息
        map.put("user", "user");
        executorParam = JacksonUtil.writeValueAsString(map);

        JobTriggerPoolHelper.trigger(id, TriggerTypeEnum.MANUAL, -1, null, executorParam, addressList);
        return ReturnT.SUCCESS;
    }
}
